<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>访客管理系统</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd/X-admin/css/font.css">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/3rd/X-admin/css/xadmin.css">
        <script type="text/javascript" src="${pageContext.request.contextPath}/3rd/X-admin/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/3rd/X-admin/js/xadmin.js"></script>
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">
                            <span class="x-red">*</span>用户名称
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="name" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="age" class="layui-form-label">
                       用户年龄
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="age" name="age" required=""
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="age" class="layui-form-label">
                            <span class="x-red">*</span>手机号
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="phone" name="phone" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="age" class="layui-form-label">
                            <span class="x-red">*</span>密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="password" name="password" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="age" class="layui-form-label">
                            mac地址
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="mac" name="password"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                  <div class="layui-form-item">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="" style="    margin-left: 100px;">
                          添加
                      </button>
                  </div>
              </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;
                form.on('submit(add)',
                    function(data) {
                        var datas={name:$("#name").val(),age:$("#age").val(),phone:$("#phone").val()
                            ,password:$("#password").val()  ,mac:$("#mac").val()
                        };
                        $.post("${pageContext.request.contextPath}/visitorManager/addVisitor", datas, function (data) {
                            console.log(data);
                            var result=eval(data);
                            if (result.status==300) {
                                layer.alert("添加失败，手机号已经存在", {icon: 5});
                            }else  if (result.status==200) {
                                layer.alert("添加成功", {icon: 6 },
                                    function() {
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                        xadmin.father_reload();
                                    });
                            } else {
                                layer.alert("添加失败", { icon: 5 },
                                    function() {
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    });
                            }
                        });
                        return false;
                    });
            });
        </script>
    </body>

</html>
